﻿using ApiGateway;
using HttpApiGateway;
using HttpApiGateway.Model;
using RpcClient;
using RpcHelper.Validate;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Gateway.Controller
{
    /// <summary>
    /// 负载均衡方案
    /// </summary>
    internal class TransmitController : ApiController
    {
        private readonly IServerTransmitService _Service;

        public TransmitController(IServerTransmitService service)
        {
            this._Service = service;
        }
        /// <summary>
        /// 添加服务节点负载方案
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        public long AddNode(TransmitBasicAdd add)
        {
            return this._Service.Add(add);
        }
        /// <summary>
        /// 添加节点类型负载方案
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        public long Add(TransmitSchemeAdd add)
        {
            return this._Service.Add(add);
        }
        /// <summary>
        /// 删除方案
        /// </summary>
        /// <param name="id"></param>
        public void Delete([NullValidate("rpc.store.transmit.id.null")]long id)
        {
            _Service.Delete(id);
        }
        /// <summary>
        /// 获取方案
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ServerTransmitConfig Get([NullValidate("rpc.store.transmit.id.null")] long id)
        {
            return _Service.Get(id);
        }
        /// <summary>
        /// 查询方案
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public PagingResult<ServerTransmitDatum>Query(PagingParam<TransmitQueryParam> query)
        {
            ServerTransmitDatum[] list= _Service.Query(query.Param, query.ToBasicPaging(), out long count);
            return new PagingResult<ServerTransmitDatum>(list, count);
        }
        /// <summary>
        /// 修改方案
        /// </summary>
        /// <param name="set"></param>
        public void Set(LongParam<TransmitSetParam> set)
        {
            _Service.Set(set.Id, set.Param);
        }
        /// <summary>
        /// 设置方案是否启用
        /// </summary>
        /// <param name="set"></param>
        public void SetIsEnable(LongParam<bool> set)
        {
            _Service.SetIsEnable(set.Id, set.Param);
        }
    }
}
